#coding=utf-8
import os
from stscraper import price_head
from stutils import *
from stvalidator import *
set_django_environ()
from stdj.stock.models import *

start_date = '2007-12-16'
for s in Share.objects.order_by('code'):
    fn = '/home/jay/temp/lastweek/%s.csv'%s.code
    if not os.path.exists(fn):
        continue
    data = csv2data(fn)
    
    fn2 = '/home/jay/stockdata/histprice/%s.csv'%s.code
    data2 = csv2data(fn2)[1:]
    
    index = 0
    for i in range(len(data2)):
        exdate = data2[i][0]
        if exdate > start_date:
            index = i 
            break
    data3 = data2[:index] + data2
    
    data2csv(data3, price_head, fn)
    print s
     
        